<?php if (!defined('TL_ROOT')) die('You cannot access this file directly!');

/**
 * Contao Open Source CMS
 * Copyright (C) 2005-2011 Leo Feyer
 *
 * Formerly known as TYPOlight Open Source CMS.
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program. If not, please visit the Free
 * Software Foundation website at <http://www.gnu.org/licenses/>.
 *
 * PHP version 5
 * @copyright  2011 Andreas Koob 
 * @author     Andreas Koob 
 * @package    tasks 
 * @license    LGPL 
 * @filesource
 */


/**
 * Class projectlist 
 *
 * @copyright  2011 Andreas Koob 
 * @author     Andreas Koob 
 * @package    Controller
 */
class tm_functions extends frontend
{
	//###########################################################################
	//Task functions
	//###########################################################################
	public function createTask($pid,$title,$description,$task_type,$created_user)
	{
		$arrSettask = array
					(
						'pid' => $pid,
						'title' => $title,
						'description' => $description,
						'task_type' => $task_type,
						'created_date' => time(),
						'created_time' => time(),
						'created_user' => $created_user,
					);
		$insertId = $this->Database->prepare("INSERT INTO tl_tm_tasks %s")->set($arrSettask)->execute()->insertId;
	}
	
	//###########################################################################
	//Member functions
	//###########################################################################
	public function getMemberInformation()
	{
		$this->import('FrontendUser', 'Member');
		$user=array(
				'id'=>$this->Member->id,
				'firstname'=>$this->Member->firstname,
				'lastname'=>$this->Member->lastname,
				'username'=>$this->Member->username
		);
		if(FE_USER_LOGGED_IN){$user['logged_in']=true;}else{$user['logged_in']=false;}
		return $user;
	}
	
	//###########################################################################
	//Other functions
	//###########################################################################
	public function checkForChangedEntries($arrOld,$arrNew)
	{
		$arrChanges=array(
			'changed'=>0,
			'added_changed'=>0,
			'added'=>array(),
			'removed_changed'=>0,
			'removed'=>array()
		);
		//Check for added entries
		for($i=0;$i<=count($arrNew);$i++)
		{
			if(!in_array($arrNew[$i],$arrOld))
			{
				if($arrNew[$i]!='')
				{
					$arrChanges['changed']=1;
					$arrChanges['added_changed']=1;
					$arrChanges['added'][]=$arrNew[$i];
				}
				
			}
		}
		//Check for deleted entries
		for($i=0;$i<=count($arrOld);$i++)
		{
			if(!in_array($arrOld[$i],$arrNew))
			{
				if($arrOld[$i]!='')
				{
					$arrChanges['changed']=1;
					$arrChanges['removed_changed']=1;
					$arrChanges['removed'][]=$arrOld[$i];
				}
				
			}
		}
		return $arrChanges;
	}
}

?>